package com.payutil;


import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class WXPayExample {

    public static void main(String[] args) throws Exception {

        MyWXPayConfig config = new MyWXPayConfig();
        WXPay wxpay = new WXPay(config);

        Map<String, String> data = new HashMap<String, String>();
        data.put("body", "腾讯充值中心-QQ会员充值");
        data.put("out_trade_no", "2016090910595900000122");
        data.put("total_fee", "1");
        data.put("spbill_create_ip", "123.12.12.123");
        data.put("notify_url", "http://www.example.com/wxpay/notify");
        data.put("trade_type", "JSAPI");  // 此处指定为扫码支付
//        data.put("nonce_str", "5K8264ILTKCH16CQ2502SI8ZNMTM67VS");
//        data.put("sign", "DC181E252201E98DF65734A631B04470");
        data.put("openid", "o0fM1wwrng93CsI_PGb9V4-1aMZc");




        try {
            Map<String, String> resp = wxpay.unifiedOrder(data);
            System.out.println(resp);
            Map<String, String> qdData = new HashMap<String, String>();
            qdData.put("appId", "wx4c1b026545f7722f");
            qdData.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
            qdData.put("nonceStr", UUID.randomUUID().toString());
            qdData.put("package", "prepay_id=" + resp.get("prepay_id"));
            qdData.put("signType", "MD5");
            String sign = WXPayUtil.generateSignature(qdData, config.getKey(), WXPayConstants.SignType.MD5);
            qdData.put("paySign", sign);
            System.out.println(JSON.toJSON(qdData));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}